import time


def bubble_sort(nums):
    a = True
    while a:
        a = False
        for i in range(len(nums) - 1):
            if nums[i] > nums[i + 1]:
                nums[i], nums[i + 1] = nums[i + 1], nums[i]
                a = True


def read2list(filename):
    file = open(filename, 'r')
    data = file.readlines()
    return data


def read2list_int(filename):
    file = open(filename, 'r')
    data = file.readlines()
    data = list(map(int, data))
    return data


data = read2list("list.txt")
print(data)
bubble_sort(data)
print(data)
data = [62, 12, 2, 7, 6]
print(data)
bubble_sort(data)
print(data)

m1 = read2list_int("m1_sorted.txt")
m2 = read2list_int("m2_reverse.txt")
m3 = read2list_int("m3_shuffle.txt")
t_start = time.time()
bubble_sort(m1)
print(m1)
t_finish = time.time()
print("Время", round((t_finish - t_start) * 1000))
t_start = time.time()
bubble_sort(m2)
print(m2)
t_finish = time.time()
print("Время", round((t_finish - t_start) * 1000))
t_start = time.time()
bubble_sort(m3)
print(m3)
t_finish = time.time()
print("Время", round((t_finish - t_start) * 1000))

